package com.hundsun.cprs.yyt.util;

import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.VerticalAlignment;


public class ExcelExportUtil {
    
    public static final Long PAGE_ROW_NUM = 65000L;
    /**
     * 导出准备
     * @param response
     * @param fileName
     * @throws UnsupportedEncodingException
     */
    public static void prepareResponse4Export(HttpServletResponse response,
                                              String fileName) throws UnsupportedEncodingException {
        // 做一些准备工作
        response.setContentType("application/vnd.ms-excel;charset=UTF-8");
        String fn = new String((fileName + ".xls").getBytes("GBK"), "ISO-8859-1");
        response.setHeader("Content-Disposition", "attachment;filename=\"" + fn + "\"");
        response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
        response.setHeader("Pragma", "public");
        response.setDateHeader("Expires", (System.currentTimeMillis() + 1000));
    }

    /**
     * 导出准备
     * @param response
     * @param fileName
     * @throws UnsupportedEncodingException
     */
    public static void prepareResponse4ExportWithNoCache(HttpServletResponse response,
                                                         String fileName) throws UnsupportedEncodingException {
        // 不要缓存，
        response.setContentType("application/vnd.ms-excel;charset=UTF-8");
        String fn = new String((fileName + ".xls").getBytes("GBK"), "ISO-8859-1");
        response.setHeader("Content-Disposition", "attachment;filename=\"" + fn + "\"");
        response.setHeader("Cache-Control", "no-cache");
        response.setHeader("Pragma", "no-cache");
        response.setDateHeader("Expires", -1);
    }

    /**
     * 填充单元格.
     * @param row
     * @param cellnum
     * @param style
     * @param value
     */
    public static void fillCell(HSSFRow row, int cellnum, HSSFCellStyle style, String value) {
        HSSFCell cell = row.createCell(cellnum);
        cell.setCellStyle(style);
        cell.setCellValue(value); //设置Excel工作表的值  
    }

    /**
     * 填充单元格.
     * @param row
     * @param cellnum
     * @param style
     * @param successAmount
     */
    public static void fillCell(HSSFRow row, int cellnum, HSSFCellStyle style, Long value) {
        HSSFCell cell = row.createCell(cellnum);
        cell.setCellStyle(style);
        cell.setCellValue(value); //设置Excel工作表的值  
    }

    /**
     * 得到加粗字体格式
     * @param workbook2003
     * @return
     */
    public static HSSFCellStyle getBoldCellStyle(HSSFWorkbook workbook2003) {
        HSSFCellStyle styleBold = getNomalCellStyle(workbook2003);
        HSSFFont font = workbook2003.createFont();
        font.setFontHeightInPoints((short) 10);
        font.setFontName("宋体");
        font.setBold(true);//加粗
        styleBold.setFont(font);
        return styleBold;
    }

    /**
     * 得到标题格式
     * @param workbook2003
     * @return
     */
    public static HSSFCellStyle getTitleCellStyle(HSSFWorkbook workbook2003) {
        HSSFCellStyle styleTitle = getNomalCellStyle(workbook2003);
        HSSFFont font = workbook2003.createFont();
        font.setFontHeightInPoints((short) 14);
        font.setFontName("宋体");
        font.setBold(true);
        styleTitle.setFont(font);
        styleTitle.setAlignment(HorizontalAlignment.CENTER);// 水平居中
        return styleTitle;
    }

    /**
     * 得到普通字体格式
     * @param workbook2003
     * @return
     */
    public static HSSFCellStyle getNomalCellStyle(HSSFWorkbook workbook2003) {
        HSSFCellStyle style = workbook2003.createCellStyle();
        style.setBorderBottom(BorderStyle.THIN);//下边框       
        style.setBorderLeft(BorderStyle.THIN);//左边框       
        style.setBorderRight(BorderStyle.THIN);//右边框       
        style.setBorderTop(BorderStyle.THIN);//上边框
        style.setVerticalAlignment(VerticalAlignment.CENTER);//垂直居中
        HSSFFont font = workbook2003.createFont();
        font.setFontHeightInPoints((short) 10);
        font.setFontName("宋体");
        style.setFont(font);
        return style;
    }

    /**
     * 导出数据
     * key:data-要导出的数据   property-要导出的属性名称   column-每列的标题
     * @param title excel的标题
     * @param map
     */
    @SuppressWarnings({ "unchecked" })
    public static void exportData(Map<String, List<?>> map, String title,
                                  HttpServletResponse response) throws IOException {
        try {
            ExcelExportUtil.prepareResponse4Export(response, title);
            HSSFWorkbook workbook2003 = new HSSFWorkbook();// 创建Excel2003文件对象
            List<Object> list = (List<Object>) map.get("data");//要导出的数据
            List<String> propertyList = (List<String>) map.get("property");//要得到的属性名称
            //List<String> methodList = getMethod(propertyList);//属性名称的方法开头
            List<String> columnList = (List<String>) map.get("column");//每列的标题

            int size = list.size();//要导出的数据大小
            int pageSize = 65000; //每个sheet的数量
            int page = (size - 1) / pageSize;
            for (int i = 0; i <= page; i++) {
                HSSFSheet sheet = workbook2003.createSheet("第" + (i + 1) + "页");

                sheet.setDefaultColumnWidth(20);
                HSSFRow row = null;
                HSSFCellStyle cellStyle = workbook2003.createCellStyle();
                HSSFCellStyle titleStyle = getNomalCellStyle(workbook2003);

                // 表头
                row = sheet.createRow(0);
                for (int j = 0; j < columnList.size(); j++) {
                    fillCell(row, j, titleStyle, columnList.get(j));
                }

                int startIndex = i * pageSize;
                int endIndex = (i + 1) * pageSize > size ? size : (i + 1) * pageSize;
                List<Object> subList = list.subList(startIndex, endIndex);//得到这个sheet可以存的数据
                for (int j = 0; j < subList.size(); j++) {
                    Object model = subList.get(j);
                    row = sheet.createRow(j + 1);
                    for (int k = 0; k < propertyList.size(); k++) {
                       /* Method method = model.getClass().getDeclaredMethod(methodList.get(k));//得到这个方法
                        Object object = method.invoke(model);*/
                        Object object = getValue(model, propertyList.get(k));
                        if (object == null || object.toString().equals("")) {
                            ExcelExportUtil.fillCell(row, k, cellStyle, "");
                        } else {
                            if (object instanceof Date) {
                            	Date date = (Date) object;
                                fillCell(row, k, cellStyle, DateUtil.convertDateToString("yyyy-MM-dd HH:mm:ss",date));
                            } else {
                                ExcelExportUtil.fillCell(row, k, cellStyle, object.toString());
                            }
                        }
                    }
                }
            }

            // 输出
            OutputStream out = response.getOutputStream();
            workbook2003.write(out);
            out.flush();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 导出数据
     * key:data-要导出的数据   property-要导出的属性名称   column-每列的标题
     * @param title excel的标题
     * @param map
     */
    @SuppressWarnings({ "unchecked"})
    public static void exportDataAndSum(Map<String, List<?>> map, String title,
                                  HttpServletResponse response) throws IOException {
        try {
            ExcelExportUtil.prepareResponse4Export(response, title);
            HSSFWorkbook workbook2003 = new HSSFWorkbook();// 创建Excel2003文件对象
            List<Object> list = (List<Object>) map.get("data");//要导出的数据
            List<Object> sumList = (List<Object>) map.get("sum");//要导出的数据

            List<String> propertyList = (List<String>) map.get("property");//要得到的属性名称
            //List<String> methodList = getMethod(propertyList);//属性名称的方法开头
            List<String> columnList = (List<String>) map.get("column");//每列的标题
            List<String> dataSumList = (List<String>) map.get("sumListData");//汇总的数值

            int size = list.size();//要导出的数据大小
            int pageSize = 65000; //每个sheet的数量
            int page = (size - 1) / pageSize;

            for (int i = 0; i <= page; i++) {
                HSSFSheet sheet = workbook2003.createSheet("第" + (i + 1) + "页");

                sheet.setDefaultColumnWidth(20);
                HSSFRow row = null;
                HSSFCellStyle cellStyle = workbook2003.createCellStyle();
                HSSFCellStyle titleStyle = getNomalCellStyle(workbook2003);

                // 表头
                row = sheet.createRow(0);
                for (int j = 0; j < columnList.size(); j++) {
                    fillCell(row, j, titleStyle, columnList.get(j));
                }

                int startIndex = i * pageSize;
                int endIndex = (i + 1) * pageSize > size ? size : (i + 1) * pageSize;
                List<Object> subList = list.subList(startIndex, endIndex);//得到这个sheet可以存的数据
                for (int j = 0; j < subList.size(); j++) {
                    Object model = subList.get(j);
                    row = sheet.createRow(j + 1);
                    for (int k = 0; k < propertyList.size(); k++) {
                       /* Method method = model.getClass().getDeclaredMethod(methodList.get(k));//得到这个方法
                        Object object = method.invoke(model);*/
                        Object object = getValue(model, propertyList.get(k));
                        if (object == null || object.toString().equals("")) {
                            ExcelExportUtil.fillCell(row, k, cellStyle, "");
                        } else {
                            if (object instanceof Date) {
                                Date date = (Date) object;
                                fillCell(row, k, cellStyle, DateUtil.convertDateToString("yyyy-MM-dd HH:mm:ss",date));
                            } else {
                                ExcelExportUtil.fillCell(row, k, cellStyle, object.toString());
                            }
                        }
                    }
                }

                row = sheet.createRow(subList.size() + 2);
                DecimalFormat df = new DecimalFormat("0.00");
                if(dataSumList.size()==4) {
                    if (dataSumList.get(0) != null && !dataSumList.get(0).equals("")) {
                        ExcelExportUtil.fillCell(row, propertyList.size() - 4, cellStyle, dataSumList.get(0).toString() + ":" + df.format(sumList.get(0)));
                    }

                    if (dataSumList.get(1) != null && !dataSumList.get(1).equals("")) {
                        ExcelExportUtil.fillCell(row, propertyList.size() - 3, cellStyle, dataSumList.get(1).toString() + ":" + df.format(sumList.get(1)));
                    }

                    if (dataSumList.get(2) != null && !dataSumList.get(2).equals("")) {
                        ExcelExportUtil.fillCell(row, propertyList.size() - 2, cellStyle, dataSumList.get(2).toString() + ":" + df.format(sumList.get(2)));
                    }

                    if (dataSumList.get(3) != null && !dataSumList.get(3).equals("")) {
                        ExcelExportUtil.fillCell(row, propertyList.size() - 1, cellStyle, dataSumList.get(3).toString() + ":" + df.format(sumList.get(3)));
                    }
                }else if (dataSumList.size()==3){
                    if (dataSumList.get(0) != null && !dataSumList.get(0).equals("")) {
                        ExcelExportUtil.fillCell(row, propertyList.size() - 3, cellStyle, dataSumList.get(0).toString() + ":" + df.format(sumList.get(0)));
                    }

                    if (dataSumList.get(1) != null && !dataSumList.get(1).equals("")) {
                        ExcelExportUtil.fillCell(row, propertyList.size() - 2, cellStyle, dataSumList.get(1).toString() + ":" + df.format(sumList.get(1)));
                    }

                    if (dataSumList.get(2) != null && !dataSumList.get(2).equals("")) {
                        ExcelExportUtil.fillCell(row, propertyList.size() - 1, cellStyle, dataSumList.get(2).toString() + ":" + df.format(sumList.get(2)));
                    }
                }else if (dataSumList.size()==2){
                    if (dataSumList.get(0) != null && !dataSumList.get(0).equals("")) {
                        ExcelExportUtil.fillCell(row, propertyList.size() - 2, cellStyle, dataSumList.get(0).toString() + ":" + df.format(sumList.get(0)));
                    }

                    if (dataSumList.get(1) != null && !dataSumList.get(1).equals("")) {
                        ExcelExportUtil.fillCell(row, propertyList.size() - 1, cellStyle, dataSumList.get(1).toString() + ":" + df.format(sumList.get(1)));
                    }
                }else if (dataSumList.size()==1){
                    if (dataSumList.get(0) != null && !dataSumList.get(0).equals("")) {
                        ExcelExportUtil.fillCell(row, propertyList.size() - 1, cellStyle, dataSumList.get(0).toString() + ":" + df.format(sumList.get(0)));
                    }
                }
            }


            // 输出
            OutputStream out = response.getOutputStream();
            workbook2003.write(out);
            out.flush();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 导出数据2
     * key:data-要导出的数据   property-要导出的属性名称   column-每列的标题
     * @param title excel的标题
     * @param map
     */
    @SuppressWarnings({ "unchecked"})
    public static void exportDataAndSum2(Map<String, List<?>> map, String title,
                                        HttpServletResponse response) throws IOException {
        try {
            ExcelExportUtil.prepareResponse4Export(response, title);
            HSSFWorkbook workbook2003 = new HSSFWorkbook();// 创建Excel2003文件对象
            List<Object> list = (List<Object>) map.get("data");//要导出的数据
            List<Object> sumList = (List<Object>) map.get("sum");//要导出的数据

            List<String> propertyList = (List<String>) map.get("property");//要得到的属性名称
            //List<String> methodList = getMethod(propertyList);//属性名称的方法开头
            List<String> columnList = (List<String>) map.get("column");//每列的标题
            List<String> dataSumList = (List<String>) map.get("sumListData");//汇总的数值

            int size = list.size();//要导出的数据大小
            int pageSize = 65000; //每个sheet的数量
            int page = (size - 1) / pageSize;

            for (int i = 0; i <= page; i++) {
                HSSFSheet sheet = workbook2003.createSheet("第" + (i + 1) + "页");

                sheet.setDefaultColumnWidth(20);
                HSSFRow row = null;
                HSSFCellStyle cellStyle = workbook2003.createCellStyle();
                HSSFCellStyle titleStyle = getNomalCellStyle(workbook2003);

                // 表头
                row = sheet.createRow(0);
                for (int j = 0; j < columnList.size(); j++) {
                    fillCell(row, j, titleStyle, columnList.get(j));
                }

                int startIndex = i * pageSize;
                int endIndex = (i + 1) * pageSize > size ? size : (i + 1) * pageSize;
                List<Object> subList = list.subList(startIndex, endIndex);//得到这个sheet可以存的数据
                for (int j = 0; j < subList.size(); j++) {
                    Object model = subList.get(j);
                    row = sheet.createRow(j + 1);
                    for (int k = 0; k < propertyList.size(); k++) {
                       /* Method method = model.getClass().getDeclaredMethod(methodList.get(k));//得到这个方法
                        Object object = method.invoke(model);*/
                        Object object = getValue(model, propertyList.get(k));
                        if (object == null || object.toString().equals("")) {
                            ExcelExportUtil.fillCell(row, k, cellStyle, "");
                        } else {
                            if (object instanceof Date) {
                                Date date = (Date) object;
                                fillCell(row, k, cellStyle, DateUtil.convertDateToString("yyyy-MM-dd HH:mm:ss",date));
                            } else {
                                ExcelExportUtil.fillCell(row, k, cellStyle, object.toString());
                            }
                        }
                    }
                }

                row = sheet.createRow(subList.size() + 2);
                DecimalFormat df = new DecimalFormat("0.00");
                if(dataSumList.size()==4) {
                    if (dataSumList.get(0) != null && !dataSumList.get(0).equals("")) {
                        ExcelExportUtil.fillCell(row,0, cellStyle, dataSumList.get(0).toString() + ":" + df.format(sumList.get(0)));
                    }

                    if (dataSumList.get(1) != null && !dataSumList.get(1).equals("")) {
                        ExcelExportUtil.fillCell(row, 1, cellStyle, dataSumList.get(1).toString() + ":" + df.format(sumList.get(1)));
                    }

                    if (dataSumList.get(2) != null && !dataSumList.get(2).equals("")) {
                        ExcelExportUtil.fillCell(row, 2, cellStyle, dataSumList.get(2).toString() + ":" + df.format(sumList.get(2)));
                    }

                    if (dataSumList.get(3) != null && !dataSumList.get(3).equals("")) {
                        ExcelExportUtil.fillCell(row, 3, cellStyle, dataSumList.get(3).toString() + ":" + df.format(sumList.get(3)));
                    }
                }else if (dataSumList.size()==3){
                    if (dataSumList.get(0) != null && !dataSumList.get(0).equals("")) {
                        ExcelExportUtil.fillCell(row, 0, cellStyle, dataSumList.get(0).toString() + ":" + df.format(sumList.get(0)));
                    }

                    if (dataSumList.get(1) != null && !dataSumList.get(1).equals("")) {
                        ExcelExportUtil.fillCell(row, 1, cellStyle, dataSumList.get(1).toString() + ":" + df.format(sumList.get(1)));
                    }

                    if (dataSumList.get(2) != null && !dataSumList.get(2).equals("")) {
                        ExcelExportUtil.fillCell(row, 2, cellStyle, dataSumList.get(2).toString() + ":" + df.format(sumList.get(2)));
                    }
                }else if (dataSumList.size()==2){
                    if (dataSumList.get(0) != null && !dataSumList.get(0).equals("")) {
                        ExcelExportUtil.fillCell(row, 0, cellStyle, dataSumList.get(0).toString() + ":" + df.format(sumList.get(0)));
                    }

                    if (dataSumList.get(1) != null && !dataSumList.get(1).equals("")) {
                        ExcelExportUtil.fillCell(row, 1, cellStyle, dataSumList.get(1).toString() + ":" + df.format(sumList.get(1)));
                    }
                }else if (dataSumList.size()==1){
                    if (dataSumList.get(0) != null && !dataSumList.get(0).equals("")) {
                        ExcelExportUtil.fillCell(row, 0, cellStyle, dataSumList.get(0).toString() + ":" + df.format(sumList.get(0)));
                    }
                }
            }


            // 输出
            OutputStream out = response.getOutputStream();
            workbook2003.write(out);
            out.flush();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 获取属性值，支持按属性path获取
     * @param source
     * @param propertyName
     * @return
     */
    private static Object getValue(Object source,String propertyName){
        try {
            if(propertyName.indexOf(".") > 0){
                String firstPropName = propertyName.substring(0, propertyName.indexOf("."));
                String remainingPropName = propertyName.substring(propertyName.indexOf(".") + 1);
                Method method = source.getClass().getMethod(getMethod(firstPropName));
                return getValue(method.invoke(source), remainingPropName);
            }
            Method method = source.getClass().getMethod(getMethod(propertyName));
            return method.invoke(source);
        } catch (NoSuchMethodException e) {
             e.printStackTrace();
        } catch (SecurityException e) {
             e.printStackTrace();
        } catch (IllegalAccessException e) {
             e.printStackTrace();
        } catch (IllegalArgumentException e) {
             e.printStackTrace();
        } catch (InvocationTargetException e) {
             e.printStackTrace();
        }
        return null;
    }

    private static List<String> getMethod(List<?> list) {
        List<String> returnList = new ArrayList<String>();
        for (Object param : list) {
            String returnParam = getMethod(param.toString());
            returnList.add(returnParam);
        }
        return returnList;
    }
    
    private static String getMethod(String param) {
        return "get" + param.toString().substring(0, 1).toUpperCase() + param.toString().substring(1);
    }
    
    

    public static void main(String[] args) throws SecurityException, NoSuchMethodException,
                                           IllegalArgumentException, IllegalAccessException,
                                           InvocationTargetException {
       /* List<Stock> list = new ArrayList<Stock>();
        Stock stock = new Stock();
        stock.setId(0L);
        list.add(stock);
        Object object = list.get(0);
        Method method = object.getClass().getDeclaredMethod("getId");
        Object o = method.invoke(stock);
        System.out.println(o);*/
    }

    /**
     * 生成excel文件并上传到服务器
     *
     * */
    public static void uploadExcel(Map<String, List<?>> map, String title,
                                        HttpServletResponse response,String uploadRoot) throws IOException {
        try {
            ExcelExportUtil.prepareResponse4Export(response, title);
            HSSFWorkbook workbook2003 = new HSSFWorkbook();// 创建Excel2003文件对象
            List<Object> list = (List<Object>) map.get("data");//要导出的数据
            List<Object> sumList = (List<Object>) map.get("sum");//要导出的数据

            List<String> propertyList = (List<String>) map.get("property");//要得到的属性名称
            //List<String> methodList = getMethod(propertyList);//属性名称的方法开头
            List<String> columnList = (List<String>) map.get("column");//每列的标题
            List<String> dataSumList = (List<String>) map.get("sumListData");//汇总的数值

            int size = list.size();//要导出的数据大小
            int pageSize = 65000; //每个sheet的数量
            int page = (size - 1) / pageSize;

            for (int i = 0; i <= page; i++) {
                HSSFSheet sheet = workbook2003.createSheet("第" + (i + 1) + "页");

                sheet.setDefaultColumnWidth(20);
                HSSFRow row = null;
                HSSFCellStyle cellStyle = workbook2003.createCellStyle();
                HSSFCellStyle titleStyle = getNomalCellStyle(workbook2003);

                // 表头
                row = sheet.createRow(0);
                for (int j = 0; j < columnList.size(); j++) {
                    fillCell(row, j, titleStyle, columnList.get(j));
                }

                int startIndex = i * pageSize;
                int endIndex = (i + 1) * pageSize > size ? size : (i + 1) * pageSize;
                List<Object> subList = list.subList(startIndex, endIndex);//得到这个sheet可以存的数据
                for (int j = 0; j < subList.size(); j++) {
                    Object model = subList.get(j);
                    row = sheet.createRow(j + 1);
                    for (int k = 0; k < propertyList.size(); k++) {
                       /* Method method = model.getClass().getDeclaredMethod(methodList.get(k));//得到这个方法
                        Object object = method.invoke(model);*/
                        Object object = getValue(model, propertyList.get(k));
                        if (object == null || object.toString().equals("")) {
                            ExcelExportUtil.fillCell(row, k, cellStyle, "");
                        } else {
                            if (object instanceof Date) {
                                Date date = (Date) object;
                                fillCell(row, k, cellStyle, DateUtil.convertDateToString("yyyy-MM-dd HH:mm:ss",date));
                            } else {
                                ExcelExportUtil.fillCell(row, k, cellStyle, object.toString());
                            }
                        }
                    }
                }

                row = sheet.createRow(subList.size() + 2);
                DecimalFormat df = new DecimalFormat("0.00");
                if(dataSumList.size()==4) {
                    if (dataSumList.get(0) != null && !dataSumList.get(0).equals("")) {
                        ExcelExportUtil.fillCell(row, propertyList.size() - 4, cellStyle, dataSumList.get(0).toString() + ":" + df.format(sumList.get(0)));
                    }

                    if (dataSumList.get(1) != null && !dataSumList.get(1).equals("")) {
                        ExcelExportUtil.fillCell(row, propertyList.size() - 3, cellStyle, dataSumList.get(1).toString() + ":" + df.format(sumList.get(1)));
                    }

                    if (dataSumList.get(2) != null && !dataSumList.get(2).equals("")) {
                        ExcelExportUtil.fillCell(row, propertyList.size() - 2, cellStyle, dataSumList.get(2).toString() + ":" + df.format(sumList.get(2)));
                    }

                    if (dataSumList.get(3) != null && !dataSumList.get(3).equals("")) {
                        ExcelExportUtil.fillCell(row, propertyList.size() - 1, cellStyle, dataSumList.get(3).toString() + ":" + df.format(sumList.get(3)));
                    }
                }else if (dataSumList.size()==3){
                    if (dataSumList.get(0) != null && !dataSumList.get(0).equals("")) {
                        ExcelExportUtil.fillCell(row, propertyList.size() - 3, cellStyle, dataSumList.get(0).toString() + ":" + df.format(sumList.get(0)));
                    }

                    if (dataSumList.get(1) != null && !dataSumList.get(1).equals("")) {
                        ExcelExportUtil.fillCell(row, propertyList.size() - 2, cellStyle, dataSumList.get(1).toString() + ":" + df.format(sumList.get(1)));
                    }

                    if (dataSumList.get(2) != null && !dataSumList.get(2).equals("")) {
                        ExcelExportUtil.fillCell(row, propertyList.size() - 1, cellStyle, dataSumList.get(2).toString() + ":" + df.format(sumList.get(2)));
                    }
                }else if (dataSumList.size()==2){
                    if (dataSumList.get(0) != null && !dataSumList.get(0).equals("")) {
                        ExcelExportUtil.fillCell(row, propertyList.size() - 2, cellStyle, dataSumList.get(0).toString() + ":" + df.format(sumList.get(0)));
                    }

                    if (dataSumList.get(1) != null && !dataSumList.get(1).equals("")) {
                        ExcelExportUtil.fillCell(row, propertyList.size() - 1, cellStyle, dataSumList.get(1).toString() + ":" + df.format(sumList.get(1)));
                    }
                }else if (dataSumList.size()==1){
                    if (dataSumList.get(0) != null && !dataSumList.get(0).equals("")) {
                        ExcelExportUtil.fillCell(row, propertyList.size() - 1, cellStyle, dataSumList.get(0).toString() + ":" + df.format(sumList.get(0)));
                    }
                }
            }

            //将文件上传至服务器
            UploadUtil.uploadExcel(workbook2003,title,uploadRoot);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
